# _*_ coding: utf-8 _*_

# @File    :   抽象工厂.py
# @Version :   xxx
# @Author  :   grit
# @Email   :   2285839445@qq.com
# @Time    :   2020/08/22 22:55:39
# Description:
import abc

# ! 产品
# * 用户表接口
class IUser(abc.ABC):
    @abc.abstractmethod
    def Insert(self):
        pass

    @abc.abstractmethod
    def GetUser(self):
        pass


class SqlServerUser(IUser):
    def Insert(self):
        print("在SQL Server中给User表增加一条记录")

    def GetUser(self):
        print("在SQL Server中给User表获取一条记录")


class AccessUser(IUser):
    def Insert(self):
        print("在Access中给User表增加一条记录")

    def GetUser(self):
        print("在Access中User表获取一条记录")


# * Department表接口
class IDepartment(abc.ABC):
    @abc.abstractmethod
    def Insert(self):
        pass

    @abc.abstractmethod
    def GetDepartment(self):
        pass


class SqlServerDepartment(IDepartment):
    def Insert(self):
        print("在SQL Server中给Department表增加一条记录")

    def GetDepartment(self):
        print("在SQL Server中Department获取一条记录")


class AccessDepartment(IDepartment):
    def Insert(self):
        print("在Access中给Department表增加一条记录")

    def GetDepartment(self):
        print("在Access中Department获取一条记录")


# ! 工厂
class IFactory(abc.ABC):
    @abc.abstractmethod
    def CreateUser(self):
        pass

    @abc.abstractmethod
    def CreateDepartment(self):
        pass


class SqlServerFactory(IFactory):
    def CreateUser(self): # 一个产品结构对应一个工厂方法
        return SqlServerUser()

    def CreateDepartment(self):
        return SqlServerDepartment()


class AccessFactory(IFactory):
    def CreateUser(self):
        return AccessUser()

    def CreateDepartment(self):
        return AccessDepartment()


# * 客户端代码
def main():
    choise = int(input("请选择数据库:"))
    factory = None
    if choise == 1:
        factory = SqlServerFactory()  # ! 创建一个 SQL数据库工厂
    elif choise == 2:
        factory = AccessFactory()  # ! 创建一个Accesee数据库工厂
    else:
        pass
    
    user = factory.CreateUser()
    department = factory.CreateDepartment()
    user.Insert()
    user.GetUser()


    department.Insert()
    department.GetDepartment()


if __name__ == "__main__":
    main()
